<script setup lang='ts' name="video-list">
import { ElPagination } from 'element-plus'
import { ref, toRefs } from 'vue'

const props = withDefaults(defineProps<{
    data?: any
    draggable?: boolean
    total: any
}>(), {
    data: () => [],
    draggable: true,
})

const emits = defineEmits(['doSort', 'pageChange'])
const { data, total } = toRefs(props)

const state = {
    page: 1,
    size: 10,
}

const pages = ref({ ...state })

function handleSizeChange(val: any) {
    console.log('size', val)
    pageChange()
}
function handleCurrentChange(val: any) {
    console.log('page', val)
    pageChange()
}

function pageChange() {
    emits('pageChange', { ...pages.value })
}

function init() {
    pages.value = { ...state }
}

function view(url = '') {
    if (url)
        window.open(url, '_block')
}

defineExpose({
    init,
})
</script>

<template>
    <template v-if="data.length">
        <div v-for="(item, index) in data"
             :key="index"
             class="video-list"
        >
            <div class="left-content">
                <img :src="item.img"
                     alt=""
                     @click="view(item.url)"
                >

                <div class="content-desc">
                    <p style="font-weight: 600;line-height: 30px;">
                        {{ item.title }}
                    </p>

                    <p style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                        {{ item.info }}
                    </p>

                    <p>分类：{{ item.catName }}</p>

                    <p>上传时间：{{ item.createTime }}</p>
                </div>
            </div>

            <div class="right-content">
                <slot name="action"
                      :index="index"
                      :row="item"
                />
            </div>
        </div>
    </template>

    <div v-else
         style="text-align: center;"
    >
        暂无数据
    </div>

    <ElPagination v-model:current-page="pages.page"
                  v-model:page-size="pages.size"
                  small
                  background
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total"
                  flex
                  mt-20
                  justify-end
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
    />
</template>

<style lang="less" scoped>
.video-list {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eef0f3;
    padding-bottom: 20px;
    margin-bottom: 20px;

    .left-content {
        display: flex;

        img {
            width: 176px;
            height: 117px;
            border: 1px solid rgb(0 0 0 / 5%);
            border-radius: 12px;
            cursor: pointer;
        }

        .content-desc {
            width: 500px;
            margin-left: 15px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
    }

    .right-content {
        display: flex;
        align-items: center;
    }
}
</style>
